#include "UnixDomainAddress.h"
#include <arpa/inet.h>
#include <cassert>
#include <cstring>
#include <netinet/in.h>
#include <string>
#include "Util.h"

namespace xncc {
namespace foundation {

    UnixDomainAddress::UnixDomainAddress(const std::string& addr) : sunPath_(addr)
    {
        shared::memZero(addr_);
        addr_.sun_family = AF_UNIX;
        assert(addr.size() < sizeof(addr_.sun_path));
        strncpy(addr_.sun_path, addr.data(), addr.size());
    }

    UnixDomainAddress::UnixDomainAddress(const struct sockaddr_un& addr) : addr_(addr), sunPath_(addr.sun_path) {}

    UnixDomainAddress::~UnixDomainAddress() = default;
}  // namespace foundation
}  // namespace xncc